using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class ContactMap : EntityTypeConfiguration<Contact>
    {
        public ContactMap()
        {
            // Primary Key
            this.HasKey(t => t.CONTACTNUM);

            // Properties
            this.Property(t => t.CONTACT1)
                .HasMaxLength(30);

            this.Property(t => t.TITLE)
                .HasMaxLength(30);

            this.Property(t => t.PHONE)
                .HasMaxLength(15);

            this.Property(t => t.EXT)
                .HasMaxLength(6);

            this.Property(t => t.FAX)
                .HasMaxLength(15);

            this.Property(t => t.ID)
                .HasMaxLength(6);

            this.Property(t => t.LAST)
                .HasMaxLength(30);

            this.Property(t => t.FIRST)
                .HasMaxLength(20);

            this.Property(t => t.File_Primary_Key)
                .HasMaxLength(10);

            // Table & Column Mappings
            this.ToTable("Contact");
            this.Property(t => t.CONTACT1).HasColumnName("CONTACT");
            this.Property(t => t.TITLE).HasColumnName("TITLE");
            this.Property(t => t.PHONE).HasColumnName("PHONE");
            this.Property(t => t.EXT).HasColumnName("EXT");
            this.Property(t => t.FAX).HasColumnName("FAX");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.LAST).HasColumnName("LAST");
            this.Property(t => t.FIRST).HasColumnName("FIRST");
            this.Property(t => t.MASTERREC).HasColumnName("MASTERREC");
            this.Property(t => t.CONTACTNUM).HasColumnName("CONTACTNUM");
            this.Property(t => t.File_Primary_Key).HasColumnName("File Primary Key");

            // Relationships
            this.HasOptional(t => t.Cust)
                .WithMany(t => t.Contacts)
                .HasForeignKey(d => d.ID);

        }
    }
}
